import pygame
import random
import sys
import time
import math

# 初始化pygame
pygame.init()

# 确保中文正常显示
pygame.font.init()
font_options = ['simsun', 'microsoftyahei', 'simhei', 'kaiti']
font_path = None
for font in font_options:
    font_path = pygame.font.match_font(font)
    if font_path:
        break
if not font_path:
    font_path = pygame.font.get_default_font()

# 游戏常量
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
FPS = 60
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 60, 60)
GREEN = (60, 255, 60)
BLUE = (60, 60, 255)
YELLOW = (255, 255, 60)
PURPLE = (180, 60, 180)
ORANGE = (255, 165, 0)
PINK = (255, 105, 180)
GOLD = (255, 215, 0)
GRAY = (150, 150, 150)
COLORS = [RED, GREEN, BLUE, YELLOW, PURPLE, ORANGE, PINK]

# 创建屏幕和时钟
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("气球点击 - 休闲小游戏")
clock = pygame.time.Clock()


# 加载背景
def create_background(level):
    """根据关卡创建不同背景"""
    background = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT))

    # 背景颜色随关卡变化
    base_color = [(245, 245, 255), (240, 245, 255), (235, 240, 255)][level % 3]
    grid_color = [(235, 235, 255), (230, 235, 255), (225, 230, 255)][level % 3]

    for y in range(0, SCREEN_HEIGHT, 20):
        for x in range(0, SCREEN_WIDTH, 20):
            if (x // 20 + y // 20) % 2 == 0:
                pygame.draw.rect(background, base_color, (x, y, 20, 20))
            else:
                pygame.draw.rect(background, grid_color, (x, y, 20, 20))
    return background


# 粒子类 - 用于气球爆炸效果
class Particle:
    def __init__(self, x, y, color):
        self.x = x
        self.y = y
        self.color = color
        self.radius = random.randint(3, 6)
        self.vx = random.uniform(-3, 3)
        self.vy = random.uniform(-3, 3)
        self.life = random.randint(15, 30)

    def update(self):
        self.x += self.vx
        self.y += self.vy
        self.life -= 1
        return self.life > 0

    def draw(self, surface):
        alpha = int(255 * (self.life / 30))
        temp_surf = pygame.Surface((self.radius * 2, self.radius * 2), pygame.SRCALPHA)
        pygame.draw.circle(temp_surf, (*self.color, alpha), (self.radius, self.radius), self.radius)
        surface.blit(temp_surf, (int(self.x - self.radius), int(self.y - self.radius)))


# 道具类
class PowerUp:
    TYPES = {
        "extra_life": {"color": GREEN, "text": "生命+1", "duration": 0},
        "slow_time": {"color": BLUE, "text": "减速", "duration": 5000},  # 5秒
        "double_score": {"color": PURPLE, "text": "双倍得分", "duration": 8000},  # 8秒
        "bomb": {"color": RED, "text": "炸弹", "duration": 0}  # 立即生效
    }

    def __init__(self, x, y):
        self.type = random.choice(list(PowerUp.TYPES.keys()))
        self.x = x
        self.y = y
        self.radius = 15
        self.color = PowerUp.TYPES[self.type]["color"]
        self.text = PowerUp.TYPES[self.type]["text"]
        self.duration = PowerUp.TYPES[self.type]["duration"]
        self.active = False
        self.activation_time = 0
        self.fall_speed = 1.0
        self.pulse = 0
        self.pulse_dir = 0.05

    def update(self):
        self.y += self.fall_speed
        self.pulse += self.pulse_dir
        if self.pulse > 0.2 or self.pulse < -0.2:
            self.pulse_dir *= -1

        # 检查是否过期
        if self.active and self.duration > 0:
            return pygame.time.get_ticks() - self.activation_time < self.duration
        return True

    def draw(self, surface):
        # 绘制道具
        current_radius = self.radius * (1 + self.pulse)
        pygame.draw.circle(surface, self.color, (int(self.x), int(self.y)), int(current_radius))
        pygame.draw.circle(surface, WHITE, (int(self.x), int(self.y)), int(current_radius), 2)

        # 绘制图标
        icon_font = get_font(12)
        icon_text = icon_font.render(self.text[0], True, WHITE)
        surface.blit(icon_text, (self.x - 5, self.y - 5))

    def is_clicked(self, pos):
        dx = pos[0] - self.x
        dy = pos[1] - self.y
        return dx * dx + dy * dy <= self.radius * self.radius

    def activate(self, game_state):
        self.active = True
        self.activation_time = pygame.time.get_ticks()

        if self.type == "extra_life":
            game_state["lives"] = min(5, game_state["lives"] + 1)
            return f"获得额外生命!"
        elif self.type == "slow_time":
            game_state["slow_time_active"] = True
            game_state["slow_time_start"] = pygame.time.get_ticks()
            return "时间变慢!"
        elif self.type == "double_score":
            game_state["double_score_active"] = True
            game_state["double_score_start"] = pygame.time.get_ticks()
            return "双倍得分激活!"
        elif self.type == "bomb":
            # 清除所有气球
            popped_count = len(game_state["balloons"])
            game_state["balloons"] = []
            game_state["score"] += popped_count * 10
            return f"炸弹清除 {popped_count} 个气球!"
        return ""


# 气球类
class Balloon:
    # 气球类型：普通、高分、快速、慢速、坚硬、迷你
    TYPES = ["normal", "high_value", "fast", "slow", "hard", "mini"]

    def __init__(self, level=1):
        self.type = random.choices(
            Balloon.TYPES,
            weights=[50, 10, 15, 10, 8, 7],  # 概率权重
            k=1
        )[0]

        # 根据类型设置属性
        if self.type == "normal":
            self.radius = random.randint(15, 30)
            self.speed = random.uniform(0.8, 2.5) * (1 + (level - 1) * 0.1)
            self.color = random.choice(COLORS)
            self.value = 10
            self.hp = 1
        elif self.type == "high_value":
            self.radius = random.randint(20, 35)
            self.speed = random.uniform(0.6, 2.0) * (1 + (level - 1) * 0.1)
            self.color = GOLD
            self.value = 50
            self.hp = 1
        elif self.type == "fast":
            self.radius = random.randint(15, 25)
            self.speed = random.uniform(2.0, 4.0) * (1 + (level - 1) * 0.1)
            self.color = RED
            self.value = 20
            self.hp = 1
        elif self.type == "slow":
            self.radius = random.randint(20, 35)
            self.speed = random.uniform(0.5, 1.5) * (1 + (level - 1) * 0.1)
            self.color = BLUE
            self.value = 15
            self.hp = 1
        elif self.type == "hard":
            self.radius = random.randint(25, 40)
            self.speed = random.uniform(1.0, 2.5) * (1 + (level - 1) * 0.1)
            self.color = GRAY
            self.value = 30
            self.hp = 2  # 需要点击两次
        elif self.type == "mini":
            self.radius = random.randint(8, 14)
            self.speed = random.uniform(1.5, 3.0) * (1 + (level - 1) * 0.1)
            self.color = PINK
            self.value = 25
            self.hp = 1

        self.x = random.randint(self.radius, SCREEN_WIDTH - self.radius)
        self.y = SCREEN_HEIGHT + self.radius
        self.popped = False
        self.particles = []
        self.pulse = 0  # 用于呼吸效果
        self.pulse_dir = 0.02  # 呼吸方向
        self.current_hp = self.hp
        self.spawn_powerup = self.type == "high_value" and random.random() < 0.5  # 高分气球有几率掉落道具

    def move(self, speed_multiplier=1):
        self.y -= self.speed * speed_multiplier
        # 呼吸效果动画
        self.pulse += self.pulse_dir
        if self.pulse > 0.15:
            self.pulse_dir = -0.02
        elif self.pulse < -0.15:
            self.pulse_dir = 0.02

    def draw(self, surface):
        if not self.popped:
            # 绘制气球主体（带呼吸效果）
            current_radius = self.radius * (1 + self.pulse)
            pygame.draw.circle(surface, self.color, (int(self.x), int(self.y)), int(current_radius))

            # 绘制类型标识
            if self.type == "hard":
                # 显示生命值
                hp_font = get_font(14)
                hp_text = hp_font.render(str(self.current_hp), True, WHITE)
                surface.blit(hp_text, (self.x - 7, self.y - 7))
            elif self.type == "high_value":
                # 显示星星标识
                star_font = get_font(16)
                star_text = star_font.render("★", True, YELLOW)
                surface.blit(star_text, (self.x - 8, self.y - 8))
            elif self.type == "fast":
                # 显示速度标识
                fast_font = get_font(14)
                fast_text = fast_font.render("⚡", True, WHITE)
                surface.blit(fast_text, (self.x - 7, self.y - 7))

            # 高光效果
            highlight_color = (min(self.color[0] + 80, 255),
                               min(self.color[1] + 80, 255),
                               min(self.color[2] + 80, 255))
            pygame.draw.circle(surface, highlight_color,
                               (int(self.x - current_radius * 0.3), int(self.y - current_radius * 0.3)),
                               int(current_radius * 0.25))

            # 气球线
            string_length = random.randint(30, 50)
            swing = math.sin(pygame.time.get_ticks() * 0.002 + self.x) * 5
            mid_y = self.y + current_radius + string_length // 2
            pygame.draw.line(surface, (50, 50, 50),
                             (self.x, self.y + current_radius),
                             (self.x + swing * 0.5, mid_y), 2)
            pygame.draw.line(surface, (50, 50, 50),
                             (self.x + swing * 0.5, mid_y),
                             (self.x + swing, self.y + current_radius + string_length), 2)

        # 绘制粒子效果
        for particle in self.particles[:]:
            if not particle.update():
                self.particles.remove(particle)
            else:
                particle.draw(surface)

    def hit(self):
        """处理气球被点击"""
        self.current_hp -= 1
        if self.current_hp <= 0:
            self.pop()
            return True  # 气球被打爆
        return False  # 气球还没爆

    def pop(self):
        if not self.popped:
            self.popped = True
            # 创建爆炸粒子
            particle_count = 15 if self.type != "mini" else 8
            for _ in range(particle_count):
                self.particles.append(Particle(self.x, self.y, self.color))

    def is_clicked(self, pos):
        if self.popped:
            return False
        dx = pos[0] - self.x
        dy = pos[1] - self.y
        return dx * dx + dy * dy <= self.radius * self.radius

    def is_off_screen(self):
        return self.y + self.radius < 0


# 按钮类
class Button:
    def __init__(self, x, y, width, height, text, font_size=30,
                 color=(60, 60, 255), hover_color=(100, 100, 255),
                 text_color=(255, 255, 255), border_radius=10):
        self.rect = pygame.Rect(x, y, width, height)
        self.text = text
        self.font_size = font_size
        self.color = color
        self.hover_color = hover_color
        self.text_color = text_color
        self.border_radius = border_radius
        self.hover = False
        self.pressed = False

    def update(self, mouse_pos, mouse_pressed):
        self.hover = self.rect.collidepoint(mouse_pos)
        self.pressed = self.hover and mouse_pressed

    def draw(self, surface):
        # 按钮颜色
        color = self.hover_color if self.hover else self.color
        if self.pressed:
            color = (min(color[0] - 30, 255), min(color[1] - 30, 255), min(color[2] - 30, 255))

        # 绘制按钮
        pygame.draw.rect(surface, color, self.rect, border_radius=self.border_radius)
        # 按钮高光
        if self.hover and not self.pressed:
            highlight = pygame.Surface((self.rect.width, self.rect.height), pygame.SRCALPHA)
            pygame.draw.rect(highlight, (255, 255, 255, 30), self.rect, border_radius=self.border_radius)
            surface.blit(highlight, self.rect.topleft)

        # 绘制文字
        font = get_font(self.font_size)
        text_surf = font.render(self.text, True, self.text_color)
        text_rect = text_surf.get_rect(center=self.rect.center)
        surface.blit(text_surf, text_rect)

    def is_clicked(self):
        return self.pressed


def get_font(size):
    """获取指定大小的字体"""
    return pygame.font.Font(font_path, size)


def game_loop():
    # 游戏状态变量
    game_state = {
        "balloons": [],
        "powerups": [],
        "score": 0,
        "lives": 3,
        "start_time": time.time(),
        "spawn_timer": 0,
        "spawn_interval": 1.0,
        "combo": 0,
        "last_pop_time": 0,
        "level": 1,
        "level_progress": 0,
        "level_required": 100,  # 升级所需分数
        "slow_time_active": False,
        "slow_time_start": 0,
        "double_score_active": False,
        "double_score_start": 0
    }

    # 创建初始背景
    background = create_background(game_state["level"])
    particles = []  # 全局粒子效果

    running = True
    while running:
        current_time = time.time()
        elapsed_time = current_time - game_state["start_time"]
        mouse_pos = pygame.mouse.get_pos()
        mouse_pressed = pygame.mouse.get_pressed()[0]
        current_ticks = pygame.time.get_ticks()

        # 检查连击是否结束
        if current_time - game_state["last_pop_time"] > 1.0 and game_state["combo"] > 0:
            game_state["combo"] = 0

        # 检查道具效果是否结束
        if game_state["slow_time_active"] and current_ticks - game_state["slow_time_start"] > 5000:
            game_state["slow_time_active"] = False
            particles.append({"text": "减速结束", "pos": (SCREEN_WIDTH // 2, 100),
                              "time": 40, "color": BLUE})

        if game_state["double_score_active"] and current_ticks - game_state["double_score_start"] > 8000:
            game_state["double_score_active"] = False
            particles.append({"text": "双倍得分结束", "pos": (SCREEN_WIDTH // 2, 100),
                              "time": 40, "color": PURPLE})

        # 计算速度乘数（考虑减速效果）
        speed_multiplier = 1 + min(2, elapsed_time / 30) * (0.5 if game_state["slow_time_active"] else 1)

        # 随时间和关卡增加难度
        game_state["spawn_interval"] = max(0.3, 1.0 - (elapsed_time / 120) - (game_state["level"] - 1) * 0.05)

        # 处理事件
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                # 左键点击气球
                for balloon in game_state["balloons"][:]:
                    if balloon.is_clicked(mouse_pos):
                        if balloon.hit():
                            # 气球被打爆
                            game_state["combo"] += 1
                            game_state["last_pop_time"] = current_time

                            # 计算得分（考虑连击和双倍得分）
                            base_score = balloon.value
                            if game_state["combo"] >= 3:
                                base_score += min(game_state["combo"] // 3, 5) * 5
                            if game_state["double_score_active"]:
                                base_score *= 2

                            game_state["score"] += base_score
                            game_state["level_progress"] += base_score

                            # 添加得分粒子
                            score_text = f"+{base_score}"
                            particles.append({"text": score_text, "pos": (mouse_pos),
                                              "time": 30,
                                              "color": GOLD if game_state["double_score_active"] else (255, 215, 0)})

                            # 连击提示
                            if game_state["combo"] >= 3:
                                particles.append(
                                    {"text": f"连击 x{game_state['combo']}!", "pos": (SCREEN_WIDTH // 2, 100),
                                     "time": 40, "color": (255, 165, 0)})

                            # 检查是否掉落道具
                            if balloon.spawn_powerup:
                                game_state["powerups"].append(PowerUp(balloon.x, balloon.y))

                # 左键点击道具
                for powerup in game_state["powerups"][:]:
                    if powerup.is_clicked(mouse_pos):
                        message = powerup.activate(game_state)
                        particles.append({"text": message, "pos": (powerup.x, powerup.y),
                                          "time": 40, "color": powerup.color})
                        game_state["powerups"].remove(powerup)

        # 生成新气球
        game_state["spawn_timer"] += 1 / FPS
        if game_state["spawn_timer"] >= game_state["spawn_interval"]:
            game_state["balloons"].append(Balloon(game_state["level"]))
            game_state["spawn_timer"] = 0

        # 检查是否升级
        if game_state["level_progress"] >= game_state["level_required"]:
            game_state["level"] += 1
            game_state["level_progress"] = 0
            game_state["level_required"] = int(game_state["level_required"] * 1.5)  # 升级所需分数递增
            background = create_background(game_state["level"])  # 更新背景
            particles.append(
                {"text": f"升级到 {game_state['level']} 级!", "pos": (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2),
                 "time": 60, "color": (180, 60, 180), "large": True})
            # 升级奖励
            game_state["lives"] = min(5, game_state["lives"] + 1)
            particles.append({"text": "获得额外生命奖励!", "pos": (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + 50),
                              "time": 50, "color": GREEN})

        # 更新气球
        for balloon in game_state["balloons"][:]:
            balloon.move(speed_multiplier)
            if balloon.is_off_screen() and not balloon.popped:
                game_state["lives"] -= 1
                game_state["balloons"].remove(balloon)
                # 添加失败提示
                particles.append({"text": "错失!", "pos": (balloon.x, 50),
                                  "time": 30, "color": (255, 60, 60)})
            elif balloon.popped and not balloon.particles:
                # 移除已爆炸且无粒子效果的气球
                game_state["balloons"].remove(balloon)

        # 更新道具
        for powerup in game_state["powerups"][:]:
            if not powerup.update() or powerup.y > SCREEN_HEIGHT + 20:
                game_state["powerups"].remove(powerup)

        # 更新粒子文本
        for p in particles[:]:
            p["time"] -= 1
            if p["time"] <= 0:
                particles.remove(p)

        # 检查游戏结束
        if game_state["lives"] <= 0:
            game_over(game_state["score"], game_state["level"])
            return

        # 绘制
        screen.blit(background, (0, 0))

        # 绘制装饰云朵
        draw_clouds()

        # 绘制所有气球
        for balloon in game_state["balloons"]:
            balloon.draw(screen)

        # 绘制所有道具
        for powerup in game_state["powerups"]:
            powerup.draw(screen)

        # 绘制粒子文本
        for p in particles:
            alpha = min(255, p["time"] * 8)
            font_size = 36 if p.get("large", False) else 24
            temp_surf = get_font(font_size).render(p["text"], True, p["color"])
            temp_surf.set_alpha(alpha)
            screen.blit(temp_surf, (p["pos"][0] - temp_surf.get_width() // 2,
                                    p["pos"][1] - temp_surf.get_height() // 2 - (30 - p["time"])))

        # 绘制分数和生命面板
        draw_panel()

        # 显示分数和生命
        score_text = get_font(30).render(f"分数: {game_state['score']}", True, WHITE)
        screen.blit(score_text, (20, 20))

        # 显示生命图标
        life_icon = pygame.Surface((30, 30), pygame.SRCALPHA)
        pygame.draw.circle(life_icon, RED, (15, 15), 10)
        for i in range(game_state["lives"]):
            screen.blit(life_icon, (20 + i * 40, 60))

        # 显示关卡和进度
        level_text = get_font(20).render(f"关卡: {game_state['level']}", True, WHITE)
        screen.blit(level_text, (20, 100))

        # 绘制关卡进度条
        progress_width = 200
        progress_height = 10
        pygame.draw.rect(screen, (100, 100, 100), (20, 130, progress_width, progress_height), border_radius=5)
        progress = min(1.0, game_state["level_progress"] / game_state["level_required"])
        pygame.draw.rect(screen, (60, 200, 60), (20, 130, progress_width * progress, progress_height), border_radius=5)

        # 显示连击
        if game_state["combo"] >= 3:
            combo_text = get_font(25).render(f"连击 x{game_state['combo']}", True, (255, 165, 0))
            screen.blit(combo_text, (SCREEN_WIDTH - 150, 20))

        # 显示激活的道具
        if game_state["slow_time_active"]:
            remaining = max(0, 5 - (current_ticks - game_state["slow_time_start"]) / 1000)
            slow_text = get_font(20).render(f"减速中: {remaining:.1f}s", True, BLUE)
            screen.blit(slow_text, (SCREEN_WIDTH - 200, 60))

        if game_state["double_score_active"]:
            remaining = max(0, 8 - (current_ticks - game_state["double_score_start"]) / 1000)
            double_text = get_font(20).render(f"双倍得分: {remaining:.1f}s", True, PURPLE)
            screen.blit(double_text, (SCREEN_WIDTH - 220, 90))

        pygame.display.flip()
        clock.tick(FPS)

    pygame.quit()
    sys.exit()


def draw_clouds():
    """绘制背景云朵"""
    cloud_positions = [
        (100, 80), (300, 50), (500, 100), (700, 70),
        (200, 200), (400, 180), (600, 220)
    ]

    for (x, y) in cloud_positions:
        # 随时间缓慢移动
        offset = pygame.time.get_ticks() * 0.0001
        cloud_x = x + math.sin(offset + x * 0.01) * 20

        # 绘制云朵
        pygame.draw.ellipse(screen, (255, 255, 255, 180), (cloud_x, y, 80, 30))
        pygame.draw.ellipse(screen, (255, 255, 255, 180), (cloud_x + 20, y - 15, 50, 30))
        pygame.draw.ellipse(screen, (255, 255, 255, 180), (cloud_x - 10, y - 10, 40, 25))


def draw_panel():
    """绘制半透明信息面板"""
    panel = pygame.Surface((SCREEN_WIDTH, 150), pygame.SRCALPHA)
    panel.fill((0, 0, 0, 100))
    screen.blit(panel, (0, 0))

    # 装饰线条
    pygame.draw.line(screen, (255, 255, 255, 30), (0, 150), (SCREEN_WIDTH, 150), 2)


def game_over(score, level):
    """游戏结束界面"""
    # 创建按钮
    restart_button = Button(SCREEN_WIDTH // 2 - 120, 350, 240, 60, "重新开始", 35,
                            (60, 180, 60), (80, 200, 80))
    quit_button = Button(SCREEN_WIDTH // 2 - 120, 430, 240, 60, "退出游戏", 35,
                         (180, 60, 60), (200, 80, 80))

    while True:
        mouse_pos = pygame.mouse.get_pos()
        mouse_pressed = pygame.mouse.get_pressed()[0]

        # 更新按钮状态
        restart_button.update(mouse_pos, mouse_pressed)
        quit_button.update(mouse_pos, mouse_pressed)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                if restart_button.hover:
                    game_loop()
                elif quit_button.hover:
                    pygame.quit()
                    sys.exit()

        screen.blit(create_background(level), (0, 0))
        draw_clouds()

        # 绘制半透明遮罩
        overlay = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT), pygame.SRCALPHA)
        overlay.fill((0, 0, 0, 120))
        screen.blit(overlay, (0, 0))

        # 绘制游戏结束信息面板
        panel = pygame.Surface((600, 450), pygame.SRCALPHA)
        panel.fill((255, 255, 255, 240))
        pygame.draw.rect(panel, (220, 220, 255), (0, 0, 600, 450), 10, border_radius=15)
        screen.blit(panel, (SCREEN_WIDTH // 2 - 300, SCREEN_HEIGHT // 2 - 225))

        # 显示游戏结束信息
        game_over_text = get_font(50).render("游戏结束", True, (180, 60, 60))
        screen.blit(game_over_text, (SCREEN_WIDTH // 2 - game_over_text.get_width() // 2, 130))

        # 显示关卡和分数
        level_text = get_font(30).render(f"达到关卡: {level}", True, BLACK)
        screen.blit(level_text, (SCREEN_WIDTH // 2 - level_text.get_width() // 2, 210))

        # 分数显示带阴影
        score_shadow = get_font(45).render(f"最终得分: {score}", True, (100, 100, 100))
        screen.blit(score_shadow, (SCREEN_WIDTH // 2 - score_shadow.get_width() // 2 + 2, 260 + 2))
        score_text = get_font(45).render(f"最终得分: {score}", True, BLACK)
        screen.blit(score_text, (SCREEN_WIDTH // 2 - score_text.get_width() // 2, 260))

        # 绘制按钮
        restart_button.draw(screen)
        quit_button.draw(screen)

        pygame.display.flip()
        clock.tick(FPS)


def main_menu():
    """游戏主菜单"""
    # 创建按钮
    start_button = Button(SCREEN_WIDTH // 2 - 150, 300, 300, 70, "开始游戏", 40)
    quit_button = Button(SCREEN_WIDTH // 2 - 150, 390, 300, 70, "退出游戏", 40,
                         (180, 60, 60), (200, 80, 80))

    title_y = 150
    title_dir = 0.5  # 标题浮动方向

    # 特殊气球展示（用于菜单装饰）
    demo_balloons = [
        Balloon(), Balloon(), Balloon()
    ]
    demo_balloons[0].type = "high_value"
    demo_balloons[0].x = 200
    demo_balloons[0].y = 400
    demo_balloons[1].type = "fast"
    demo_balloons[1].x = 400
    demo_balloons[1].y = 420
    demo_balloons[2].type = "hard"
    demo_balloons[2].x = 600
    demo_balloons[2].y = 380

    while True:
        mouse_pos = pygame.mouse.get_pos()
        mouse_pressed = pygame.mouse.get_pressed()[0]

        # 更新按钮状态
        start_button.update(mouse_pos, mouse_pressed)
        quit_button.update(mouse_pos, mouse_pressed)

        # 标题浮动动画
        title_y += title_dir
        if title_y > 160 or title_y < 140:
            title_dir *= -1

        # 更新演示气球
        for balloon in demo_balloons:
            balloon.move(0.3)
            if balloon.y < -50:
                balloon.y = SCREEN_HEIGHT + 50

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                if start_button.hover:
                    game_loop()
                elif quit_button.hover:
                    pygame.quit()
                    sys.exit()

        screen.blit(create_background(1), (0, 0))
        draw_clouds()

        # 绘制演示气球
        for balloon in demo_balloons:
            balloon.draw(screen)

        # 绘制标题
        title_text = get_font(70).render("气球点击", True, BLACK)
        title_shadow = get_font(70).render("气球点击", True, (100, 100, 100))
        screen.blit(title_shadow, (SCREEN_WIDTH // 2 - title_shadow.get_width() // 2 + 2, title_y + 2))
        screen.blit(title_text, (SCREEN_WIDTH // 2 - title_text.get_width() // 2, title_y))

        # 绘制副标题
        sub_text = get_font(25).render("一款轻松有趣的休闲小游戏", True, (60, 60, 60))
        screen.blit(sub_text, (SCREEN_WIDTH // 2 - sub_text.get_width() // 2, 230))

        # 绘制按钮
        start_button.draw(screen)
        quit_button.draw(screen)

        # 绘制游戏说明
        info_text1 = get_font(20).render("点击不同类型的气球获得分数", True, BLACK)
        info_text2 = get_font(20).render("收集道具获得特殊效果", True, BLACK)
        info_text3 = get_font(20).render("达到目标分数升级关卡", True, BLACK)
        screen.blit(info_text1, (SCREEN_WIDTH // 2 - info_text1.get_width() // 2, 480))
        screen.blit(info_text2, (SCREEN_WIDTH // 2 - info_text2.get_width() // 2, 510))
        screen.blit(info_text3, (SCREEN_WIDTH // 2 - info_text3.get_width() // 2, 540))

        pygame.display.flip()
        clock.tick(FPS)


if __name__ == "__main__":
    main_menu()
